package com.xxd.spring.boot.demo.lihonghai.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.lihonghai.Result;
import com.xxd.spring.boot.demo.lihonghai.entity.Grade;
import com.xxd.spring.boot.demo.lihonghai.entity.Student;
import com.xxd.spring.boot.demo.lihonghai.mapper.StudentMapper;
import com.xxd.spring.boot.demo.lihonghai.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping(value="/listStudent")
    public Result Studentlist(Page page, @RequestParam Map<String,Object> paramsMap){
        IPage resPage=studentService.Studentlist(page,paramsMap);
        return new Result().setData(resPage);

        /*@RequestMapping(value="/listStudent")
    public Result updateStudent(){
        List<Student> list=studentMapper.selectList(null);
        return new Result().setData(list);*/
    }



    @RequestMapping(value="/addStudent")
    public Result InsertStudent(@RequestBody Student studentenity){
        studentService.InsertStudent(studentenity);
        return new Result().success();
    }

    @RequestMapping(value="/updateStudent")
    public Result updateStudent(@RequestBody Student studentenity){
        studentService.updateStudent(studentenity);
        return new Result().success();
    }

    @RequestMapping(value="/delStudent/{id}")
    public Result delStudent(@PathVariable("id") Integer id){
        studentService.delStudent(id);
        return new Result().success();
    }

    @RequestMapping(value="/list")
    public Result list(@RequestBody Map<String,Object> params){
        List<Student> list=studentService.list(params);
        return new Result().success().setData(list);
    }

    @RequestMapping(value="/listByClassesId/{ClassesId}")
    public Result listByClassesId(@PathVariable("ClassesId") Integer classesid){
        List<Student> students = studentService.ListClassesId(classesid);
        return new Result().success().setData(students);
    }

    @RequestMapping("/infoById/{id}")
    public Result infoById(@PathVariable("id") Integer id)
    {
        Student student =studentService.infoById(id);
        return new Result().success().setData(student);
    }
}